package com.admin.business.portalWebsite.venusPortalQuestionAnswer;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 答疑记录表
 * @create: 2023-11-20 18:20:03
 **/
@Service("venusPortalQuestionAnswerService")
@Slf4j
public class VenusPortalQuestionAnswerService{

    @Resource
    VenusPortalQuestionAnswerDao venusPortalQuestionAnswerDao;

    /**
     * 添加答疑记录表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - record_id:问答记录表ID
     *                   - user_id:回答者用户ID
     *                   - user_nickname:用户昵称
     *                   - operation:回答状态：0、正常回答，1，追加问题回答，2、追加问题回答
     *                   - optimum:是否是最佳答案：0、正常回答，1，最佳答案
     *                   - content:内容：评论内容/回复内容
     *                   - fabulous:点赞数量
     *                   - comment:回答后追加评论
     *                   - existence:0、不存在，1、存在回复
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return addVenusPortalQuestionAnswer(CDO cdoRequest) {
        venusPortalQuestionAnswerDao.addVenusPortalQuestionAnswer(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新答疑记录表数据
     *
     * @param cdoRequest - id:主键
     *                   - record_id:问答记录表ID
     *                   - user_id:回答者用户ID
     *                   - user_nickname:用户昵称
     *                   - operation:回答状态：0、正常回答，1，追加问题回答，2、追加问题回答
     *                   - optimum:是否是最佳答案：0、正常回答，1，最佳答案
     *                   - content:内容：评论内容/回复内容
     *                   - fabulous:点赞数量
     *                   - comment:回答后追加评论
     *                   - existence:0、不存在，1、存在回复
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return updateVenusPortalQuestionAnswerById(CDO cdoRequest) {
        venusPortalQuestionAnswerDao.updateVenusPortalQuestionAnswerById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除答疑记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return deleteVenusPortalQuestionAnswerById(CDO cdoRequest){
        int count = venusPortalQuestionAnswerDao.deleteVenusPortalQuestionAnswerById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除答疑记录表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return deleteVenusPortalQuestionAnswer(CDO cdoRequest) {
        int count = venusPortalQuestionAnswerDao.deleteVenusPortalQuestionAnswer(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取答疑记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionAnswerById(CDO cdoRequest) {
        CDO cdoMapperResult = venusPortalQuestionAnswerDao.getVenusPortalQuestionAnswerById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取答疑记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionAnswerListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusPortalQuestionAnswerDao.getVenusPortalQuestionAnswerListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusPortalQuestionAnswerDao.getVenusPortalQuestionAnswerCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取答疑记录表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionAnswerListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusPortalQuestionAnswerDao.getVenusPortalQuestionAnswerListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusPortalQuestionAnswerDao.getVenusPortalQuestionAnswerCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
